package DBase;

import DBase.Players.Player;
import DBase.Players.ComputerPlayer;
import DBase.Players.HumanPlayer;


/**
 * 
 * @author Elya & Dana
 */
public class GameData {
    
    final int MIN_PLAYERS=2;
    final int MAX_PLAYERS=6;
    
    private int numOfPlayers;
    private Player [] players;
    private int [] shipSizeArr = {5,4,3,3,2};
    private String []shipNames;

    /**
     * Gets the array of ships names
     * @return shipNames
     */
    public String[] getShipNames() {
        return shipNames;
    }

    /**
     * Sets the array of ships names
     * @param shipNames
     */
    public void setShipNames(String[] shipNames) {
        this.shipNames = shipNames;
    }
    
    /**
     * Sets the ship name for given index
     * @param index the index where we want to change the ship name
     * @return shipNames[index] - the ship's name in that index
     */
    public String getShipNameFromIndex(int index){

        return shipNames[index];
    }
        
    
    /**
     * This function restarts the game for each player
     */
    public void restart(){
        
          for(int i =0; i < numOfPlayers; i++){
              players[i].restart();
          }
    }
    /**
     * Constructor that initializes the game data
     * @param numOfPlayers the number of players in the game
     * @param playerType integer array of players types(Human=1,Computer=2)
     * @param playersNames string array of the players names
     */
    public GameData(int numOfPlayers, int [] playerType,String[] playersNames) {
       
        this.numOfPlayers = numOfPlayers;
        
        players = new Player[numOfPlayers];
        for(int i =0; i < numOfPlayers; i++){
            if(playerType[i] == 1){
                players[i] = new HumanPlayer();
                players[i].setName(playersNames[i]);
                players[i].setPlayerTurnInGame(i);
                players[i].setNumOfRivalBoards(numOfPlayers,i);
            }
            if(playerType[i] == 2){
                players[i] = new ComputerPlayer();
                players[i].setName(playersNames[i]);
                players[i].setPlayerTurnInGame(i);
                players[i].setNumOfRivalBoards(numOfPlayers,i);
            }            
        }       
    }
    /**
     * Gets the ships sizes array
     * @return shipSizeArr
     */
    public int[] getShipSize() {
        return shipSizeArr;
    }

    /**
     * Gets the players array
     * @return players
     */
    public Player[] getPlayers() {
        return players;
    }

     /**
     * Gets the ship sizes array
     * @return ship sizes array
     */
    public int[] getShipSizeArr() {
        return shipSizeArr;
    }
    
    
}
